'use strict';
module.exports = app => {
  const apiCatchError = app.middleware.apiCatchError();
  const compatiable = app.middleware.compatiable();
  app.get('/user/changePassword', 'home.changePassword');
  // 测试呼叫中心
  // app.post('/comm/*', apiCatchError, 'call.comm');

  /* 下载导出表 */
  app.get('/_api/task-table', 'api.exportTaskTable');
  app.get('/_api/spare-money-table', 'api.checkSpareMoneyTableAvailable');
  app.get('/_api/spare-money-table/download', 'api.exportSpareMoneyTable');
  app.get('/_api/download/reservation', 'api.exportReservationTable');
  app.get('/_api/download/income', 'api.exportIncomeTable');
  app.get('/_api/exportIdcardList', 'api.exportTaskIdcard');
  /* 对后台api结果进一步处理 */
  app.get('/_api/sys/conf/tags', apiCatchError, 'home.proxySysConfTags');
  app.get('/_api/sys/versionIns/latest', apiCatchError, 'home.proxySysVersionInsLatest');

  /* 呼叫中心接口 */
  app.get('/_api/call/login', apiCatchError, 'call.login');
  app.get('/_api/call/redirect', apiCatchError, 'call.redirect');
  app.get('/_api/call/logout', apiCatchError, 'call.logout');
  app.post('/_api/call', 'call.proxy');
  app.post('/comm/oauth/token/', 'call.comm');
  app.post('/comm/*', 'call.agent');

  app.get('/_api/patient/es_search', 'home.proxyPortal');
  // 健康中心
  app.get('/_api/patients/purchase_voucher', 'home.proxyPortal');
  // 编辑健康档案
  app.put('/_api/patients/physicalExamination/:id', 'home.physicalExaminationPut');
  // 新增健康档案
  app.post('/_api/patients/:patientId/physicalExamination', 'home.physicalExaminationPost');
  // 根据服务包查询健康问询
  app.get('/_api/insurance_package/:packageId/inquiries', 'home.proxyPortal');

  function proxy(...args) {
    app.get(...args);
    app.post(...args);
    app.put(...args);
    app.del(...args);
  }

  /* 正常代理后台接口 */
  // 查询问询
  app.get('/_api/getenquiry/', 'home.proxyPortal');

  proxy('/_api/user/*', 'home.proxyUser');
  proxy('/_api/crm/*', 'home.proxyTask');
  proxy('/_api/weixin/*', 'home.proxyWeixin');

  proxy('/_api/cfg/enum/orderCancelReasonCRM', 'home.proxyPortal');
  proxy('/_api/sys/enum/taskType', 'home.proxyPortal');
  proxy('/_api/patient/:patientId/receiverAddress', 'home.proxyPortal');
  proxy('/_api/patient/:patientId/receiverAddress/*', 'home.proxyPortal');
  proxy('/_api/drugReplacement', 'home.proxyPortal');
  // 查询健康档案疾病
  proxy('/_api/patients/physicalExamination/diseases', 'home.proxyPortal');
  // 查询健康档案流水
  // proxy('/_api/patients/:patientId/physicalExaminationLogs', 'home.physicalExaminationPost');

  // 查询风险评估报告
  proxy('/_api/assessment_reports', 'home.proxyPortal');
  // 查询风险评估报告详情
  proxy('/_api/assessment_reports/:reportId', 'home.proxyPortal');

  // oss文件下载
  proxy('/_api/oss/download', 'home.proxyPortal');
  // 团险清单下载
  proxy('/_api/groupInsurance/:groupOrderId/insuranceTeamOrderInfo', 'home.proxyPortal');
  // 团险列表
  proxy('/_api/groupInsurances', 'home.proxyPortal');
  // 查询团险保险产品
  proxy('/_api/insurancePackage/insuranceProducts', 'home.proxyPortal');
  // 团险模板校验
  proxy('/_api/groupInsurance/excel/validate', 'home.proxyPortal');
  // 团险订单提交
  proxy('/_api/groupInsurance', 'home.proxyPortal');
  // 团险单详情
  proxy('/_api/groupInsurance/:id', 'home.proxyPortal');
  // 团险缴费单列表
  proxy('/_api/groupInsurance/payments', 'home.proxyPortal');
  // 团险缴费查询
  proxy('/_api/groupInsurance/payment', 'home.proxyPortal');
  // 团险缴费提交
  proxy('/_api/groupInsurance/payment/:id', 'home.proxyPortal');
  // 团险缴费
  proxy('/_api/groupInsurance/:groupOrderId/payment/:groupOrderBillid', 'home.proxyPortal');
  // 缴费会员信息下载
  proxy(
    '/_api/groupInsurance/payment/:id/groupOrderBillInfo/:groupOrderBillId/paymentMemberDownload',
    'home.proxyPortal'
  );
  // 退保会员信息下载
  proxy(
    '/_api/groupInsurance/payment/:id/groupOrderBillInfo/:groupOrderBillId/revokeMemberDownload',
    'home.proxyPortal'
  );


  // 体检前问卷
  proxy('/_api/hdDiseases', 'home.proxyPortal');
  proxy('/_api/patients/:patientId/prePhysicalQuestionnaire', 'home.prePhysicalQuestionnaire');
  proxy('/_api/patient/:patientId/insurance_order/inservice', 'home.proxyPortal');

  proxy('/_api/patients', 'home.proxyPortal');
  proxy('/_api/patients/*', 'home.proxyPortal');
  proxy('/_api/orderfills', 'home.proxyPortal');
  proxy('/_api/orderfills/*', 'home.proxyPortal');
  proxy('/_api/patients/reservationRecord/*', 'home.proxyPortal');
  proxy('/_api/doctorSchedules', 'home.proxyPortal');
  proxy('/_api/doctorSchedules/*', 'home.proxyPortal');
  proxy('/_api/billing/income/detail', 'home.proxyPortal');
  proxy('/_api/billing/income/detail/*', 'home.proxyPortal');
  proxy('/_api/message_center', 'home.proxyPortal');
  proxy('/_api/message_center/*', 'home.proxyPortal');

  app.put('/_api/health/patient/physicalExamination/:physicalExaminationId', 'proxy.updatephysicalExamination');
  app.put('/_api/health/patient/:patientId/chronic_disease', 'proxy.updateChronicDiseases');
  app.post('/_api/health/patient/:patientId/delete_chronic_disease', 'proxy.deleteChronicDiseases');
  app.post('/_api/health/patient/:patientId/physicalExamination', 'proxy.physicalExamination');
  app.get('/_api/health/upload/signature', 'proxy.uploadConfig');
  app.get('/_api/patient/businessCode/:businessCode', 'home.proxyPortal');
  app.put('/_api/patient/:patientId', 'home.proxyPortal');
  app.post('/_api/patient', 'home.proxyPortal');
  app.get('/_api/patient/insurance_order', 'home.proxyPortal');
  proxy('/_api/health/*', 'proxy.proxyHealthPortal');
  proxy('/_api/uploadImages', 'home.proxyPortal');
  app.post('/_api/orders', 'home.proxyPortal');
  app.put('/_api/orders/:orderId', 'home.proxyPortal');
  app.get('/_api/orders/:orderId/billing/reimburse', 'home.proxyPortal');
  app.post('/_api/orders/:orderId/cancel', 'home.proxyPortal');
  proxy('/_api/thirdPartyOrders', 'home.thirdPartyOrders');
  app.get('/_api/patient/:patientId/rewardpoints/record', 'home.proxyPortal');
  proxy('/_api/patient/:patientId/freight', 'home.proxyPortal');
  app.get('/_api/hospitals/:hospitalId', 'home.proxyPortal');
  app.get('/_api/hospitals/:hospitalId/paymentType', 'home.proxyPortal');
  app.post('/_api/completeOrders', 'home.proxyPortal');
  proxy('/_api/patients/:patientId/memberInfo', 'home.proxyPortal');
  app.get('/_api/patients/:patientId/welfare', 'home.proxyPortal');
  app.get('/_api/patientGradeConfig', 'home.proxyPortal');
  app.post('/_api/insurance_order/:insurOrderId/revoke', 'home.proxyPortal');
  proxy('/_api/orders/:orderId/doctorConfirmation', 'home.proxyPortal');
  proxy('/_api/orders/:orderId/expressRouteInfo', 'home.proxyPortal');
  proxy('/_api/hospitals', 'home.proxyPortal');
  // 保险
  proxy('/_api/insurance_package', 'home.proxyPortal');
  proxy('/_api/patient/insurance_order/export', 'home.proxyPortal');
  proxy('/_api/insurance_packages/*', 'home.proxyPortal');
  proxy('/_api/patient/:patientId/insuranceAccountInfo', 'home.proxyPortal');
  proxy('/_api/patient/:patientId/certification', 'home.proxyPortal');
  proxy('/_api/patient/insurance_order', 'home.proxyPortal');
  proxy('/_api/team_insurance/:insurId/download', 'api.exportInsuranceZip');
  proxy('/_api/team_insurance', 'home.proxyPortal');
  proxy('/_api/team_insurance/*', 'home.proxyPortal');
  proxy('/_api/orders/:orderId/lianou_order', 'home.proxyPortal');
  // 获取保险产品列表
  proxy('/_api/insurance/products', 'home.proxyPortal');
  // 获取保险公司
  proxy('/_api/insurance/companies', 'home.proxyPortal');
  // 查询处方
  proxy('/_api/orderDrafts', 'home.proxyPortal');

  app.get('/_api/medicOrders', 'home.proxyPortal');
  app.get('/_api/medicOrders/:id', 'home.proxyPortal');
  app.get('/_api/medicOrders/export', 'home.proxyPortal');
  app.get('/_api/team_insurance/excel', 'home.proxyPortal');

  app.get('/patients/insurance_order/:orderId', 'home.proxyPortal');
  proxy('/_api/patients', 'home.proxyPortal');
  proxy('/_api/patients/*', 'home.proxyPortal');
  proxy('/_api/orderfills', 'home.proxyPortal');
  proxy('/_api/orderfills/*', 'home.proxyPortal');
  proxy('/_api/patients/reservationRecord/*', 'home.proxyPortal');
  proxy('/_api/doctorSchedules', 'home.proxyPortal');
  proxy('/_api/doctorSchedules/*', 'home.proxyPortal');
  proxy('/_api/billing/income/detail', 'home.proxyPortal');
  proxy('/_api/billing/income/detail/*', 'home.proxyPortal');
  proxy('/_api/message_center', 'home.proxyPortal');
  proxy('/_api/message_center/*', 'home.proxyPortal');
  app.put('/_api/health/patient/physicalExamination/:physicalExaminationId', 'proxy.updatephysicalExamination');
  app.put('/_api/health/patient/:patientId/chronic_disease', 'proxy.updateChronicDiseases');
  app.post('/_api/health/patient/:patientId/delete_chronic_disease', 'proxy.deleteChronicDiseases');
  app.post('/_api/health/patient/:patientId/physicalExamination', 'proxy.physicalExamination');
  app.get('/_api/health/upload/signature', 'proxy.uploadConfig');
  app.get('/_api/patient/businessCode/:businessCode', 'home.proxyPortal');
  app.put('/_api/patient/:patientId', 'home.proxyPortal');
  app.post('/_api/patient', 'home.proxyPortal');
  app.get('/_api/patient/insurance_order', 'home.proxyPortal');
  proxy('/_api/health/*', 'proxy.proxyHealthPortal');
  proxy('/_api/uploadImages', 'home.proxyPortal');
  proxy('/_api/oss/upload', 'home.proxyPortal');
  app.post('/_api/orders', 'home.proxyPortal');
  app.put('/_api/orders/:orderId', 'home.proxyPortal');
  app.get('/_api/orders/:orderId/billing/reimburse', 'home.proxyPortal');
  app.post('/_api/orders/:orderId/cancel', 'home.proxyPortal');
  proxy('/_api/thirdPartyOrders', 'home.thirdPartyOrders');
  app.get('/_api/patient/:patientId/rewardpoints/record', 'home.proxyPortal');
  proxy('/_api/patient/:patientId/freight', 'home.proxyPortal');
  app.get('/_api/hospitals/:hospitalId', 'home.proxyPortal');
  app.get('/_api/hospitals/:hospitalId/paymentType', 'home.proxyPortal');
  app.post('/_api/completeOrders', 'home.proxyPortal');
  proxy('/_api/patients/:patientId/memberInfo', 'home.proxyPortal');
  app.get('/_api/patients/:patientId/welfare', 'home.proxyPortal');
  app.get('/_api/patientGradeConfig', 'home.proxyPortal');
  app.post('/_api/insurance_order/:insurOrderId/revoke', 'home.proxyPortal');
  proxy('/_api/orders/:orderId/doctorConfirmation', 'home.proxyPortal');
  proxy('/_api/orders/:orderId/expressRouteInfo', 'home.proxyPortal');
  proxy('/_api/hospitals', 'home.proxyPortal');
  // 保险
  proxy('/_api/insurance_package', 'home.proxyPortal');
  /**
   * 查询指定天数内是否有购药记录
   * patientId: id
   * period: 天数
   */
  proxy('/_api/patient/:patientId/pickedup_order/:period/count', 'home.proxyPortal');
  proxy('/_api/v2/insurance_order/insure/:insureOrderNo', apiCatchError, 'home.proxyPortalJson');
  proxy('/_api/insurance_order/insure/:insureOrderNo', 'home.proxyPortalJson');
  proxy('/_api/patient/insurance_order/export', 'home.proxyPortal');
  proxy('/_api/insurance_packages/*', 'home.proxyPortal');
  proxy('/_api/patient/:patientId/insuranceAccountInfo', 'home.proxyPortal');
  proxy('/_api/patient/:patientId/certification', 'home.proxyPortal');
  proxy('/_api/patient/insurance_order', 'home.proxyPortal');
  proxy('/_api/team_insurance/:insurId/download', 'api.exportInsuranceZip');
  proxy('/_api/team_insurance', 'home.proxyPortal');
  proxy('/_api/team_insurance/*', 'home.proxyPortal');
  proxy('/_api/orders/:orderId/lianou_order', 'home.proxyPortal');
  // 获取保险产品列表
  proxy('/_api/insurance/products', 'home.proxyPortal');
  // 获取保险公司
  proxy('/_api/insurance/companies', 'home.proxyPortal');
  // 查询处方
  proxy('/_api/orderDrafts', 'home.proxyPortal');
  // 查询卡密订单
  proxy('/_api/insurance_cardorder', 'home.proxyPortal');
  // 卡密销售撤单
  app.put('/_api/insurance_cardorder/:insuranceCardOrderId/revoke', 'home.proxyPortal');

  // 获取智齿坐席id
  app.get('/_api/users/:userId/agentId', 'home.proxyPortal');
  // 获取智齿外显号码
  app.get('/_api/sobot/callNumber', 'home.proxyPortal');
  // 通话记录详情
  app.get('/_api/sobotCallRecord/:callId', 'home.proxyPortal');

  app.get('/_api/insurance_order/:insurOrderId/revoke', 'home.proxyPortal');
  app.get('/_api/insurance_order/:insurOrderId/revoke/detail', 'home.proxyPortal');
  app.get('/_api/v2/patients/insurance_order/:orderId', 'home.proxyPortal');
  app.get('/_api/patients/service_order/:orderId', 'home.proxyPortal');
  app.get('/_api/patients/:patientId/insurance_order/histories', 'home.proxyPortal');
  app.get('/_api/insurance_order/fork_code', 'home.proxyPortal');
  app.get('/_api/users/:userId/insurance_package', 'home.proxyPortal');
  proxy('/_api/insurance/activation_code', 'home.proxyPortal');
  proxy('/_api/insurance/activation_code/cancel', 'home.proxyPortal');
  // 体检
  proxy('/_api/patients/:patientId/ccvdAssessment', 'home.proxyPortal');
  // 获取渠道码
  proxy('/_api/users/channelCode', 'home.proxyPortal');
  // 获取当前登录用户信息
  proxy('/_api/users/currentUserInfo', 'home.proxyPortal');
  // 获取销售渠道
  proxy('/_api/operationchannel', 'home.proxyPortal');
  // 获取体检卡列表
  app.get('/_api/hd/medicalExaminationCards', 'home.proxyPortal');
  // 获取体检卡列表
  app.get('/_api/hd/medicalExaminationCards/:productId/card', 'home.proxyPortal');
  // 体检卡回收
  app.post('/_api/hd/medicalExaminationCards/recycle', 'home.proxyPortal');
  // 体检卡上传
  app.post('/_api/hd/medicalExaminationCards/import', 'home.proxyPortal');
  // 上传体检报告
  app.post('/_api/hd/medicalExaminationCards/uploadReport', 'home.proxyPortal');
  // 查询体检报告
  app.get('/_api/hd/medicalExaminationCards/report', 'home.proxyPortal');
  // 模板下载
  app.get('/_api/hd/download/template', 'home.proxyPortal');
  // 发送体检卡
  app.post('/_api/hd/medicalExaminationCards/send', 'home.proxyPortal');
  // 绑定体检卡
  app.post('/_api/hd/medicalExaminationCards/binding', 'home.proxyPortal');
  // 导出体检卡
  app.get('/_api/hd/medicalExaminationCards/export', 'home.proxyPortal');
  // 下载卡密
  app.get('/_api/insurance_cardorder/:insuranceCardOrderId/cards/download', 'home.proxyPortal');


  // 上传呼叫信息 呼入、呼出
  app.post('/_api/sobotCallRecord', 'home.proxyPortalJsonCall');
  // 通话记录列表
  app.get('/_api/sobotCallRecord', 'home.proxyPortal');
  // 团单个人投保单撤单
  // app.put('/_api/team_insurance/:teamOrderId/revoke', 'home.proxyPortal');
  proxy('/_api/team_insurance/:teamOrderId/revoke', 'home.proxyPortal');
  // patients/{patientId}/physicalExamination 查询客户健康档案
  app.get('/_api/patients/:patientId/physicalExamination', 'home.proxyPortal');
  app.get('/_api/patients/physicalExamination/:id', 'home.proxyPortal');
  app.get('/_api/cfg/enum/diseases', 'home.proxyPortal');

  proxy('/_api/physicalExaminationOrders', 'home.proxyPortal'); // 查询体检列表
  proxy('/_api/physicalExaminationOrders/:productId', 'home.proxyPortal'); // 查询体检详情
  app.get('/_api/hd/medicalExaminationCardPackages', 'home.proxyPortal'); // 查询体检套餐

  proxy('/_api/*', 'home.proxyOld');
  /* 显示前端页面 */
  app.get('/*', compatiable, 'home.index');
};
